public class ReverseSingleList {

    static class ListNode{
        public int val;
        public ListNode next;//为什么“next”可以存储一个地址？我把名字改了行不行？
        public ListNode(int val){
            this.val = val;
        }
    }
    public ListNode head;//一个叫“head”的ListNode变量（int a）
    public ListNode reverseList(){
        if (head == null){
            return null;
        }
        if (head.next == null){
            return head;
        }
        ListNode cur = head.next;
        head.next = null;

        while (cur != null){
            ListNode curNext = cur.next;
            cur.next = head;
            head = cur;//头插过去的cur变成了新的head
            cur = curNext;//curNext变成了新的cur
        }
        return head;
    }
}
